/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.Administracion.Carreras.dataproviders;

import com.sun.data.provider.DataProviderException;
import com.sun.data.provider.FieldKey;
import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.AbstractTableDataProvider;
import com.sun.data.provider.impl.IndexRowKey;
import entidad.Parametro;
import java.util.Vector;

/**
 *
 * @author kabad
 */
public class Dp_Carrera extends AbstractTableDataProvider {

    private Vector<Parametro> listaRg_Parametro = new Vector<Parametro>();

    public Dp_Carrera() {
        agregarKey("carrera", "Carrera");
        agregarKey("especializacion", "Especialización");
        agregarKey("carrera_id", "");
    }

    private void agregarKey(String key_string, String display_name) {
        FieldKey key;
        key = new FieldKey(key_string);
        key.setDisplayName(display_name);
        addFieldKey(key);
    }

    @Override
    public Class getType(FieldKey fieldKey) throws DataProviderException {
        return String.class;
    }

    @Override
    public boolean isReadOnly(FieldKey fieldKey) throws DataProviderException {
        return false;
    }

    @Override
    public int getRowCount() throws DataProviderException {
//        return this.getListaRg_Parametro().size();
		if (listaRg_Parametro!=null)
			return listaRg_Parametro.size();
		else
			return 0;
    }

    @Override
    public Object getValue(FieldKey fieldKey, RowKey row) throws DataProviderException {
        int indice = ((IndexRowKey) row).getIndex();
        Parametro registro = (Parametro) this.getListaRg_Parametro().get(indice);
		if (fieldKey==null)
			return "";
		String fieldId = fieldKey.getFieldId();
        if (fieldId.equals("carrera")) {
            return registro.getNombre();

        } else if (fieldId.equals("especializacion")) {
            Vector<Parametro> listaEspecializacion=registro.getListaParametro();
			System.out.println("listaEspecializacion: "+listaEspecializacion);
            if (!listaEspecializacion.isEmpty()) {
                String especializacion =null;
                for (Parametro parametro : listaEspecializacion) {
					System.out.println("parametro.getNombre(): "+parametro.getNombre());
					if (especializacion==null)
						especializacion = parametro.getNombre();
					else
						especializacion += ", " +parametro.getNombre() ;
                }
                return especializacion;
            } else {
                return "";
            }

        } else if (fieldId.equals("carrera_id")) {
            return registro.getIdParametro();
        } else {
            return registro.getNombre();
        }
    }

    @Override
    public void setValue(FieldKey fieldKey, RowKey row, Object value) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canInsertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey insertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canAppendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey appendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canRemoveRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Vector<Parametro> getListaRg_Parametro() {
        return listaRg_Parametro;
    }

    public void setListaRg_Parametro(Vector<Parametro> listaRg_Parametro) {
        this.listaRg_Parametro = listaRg_Parametro;
    }
}
